import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/sp.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 设置
///
class Setting extends StatefulWidget {
  const Setting({Key? key}) : super(key: key);

  @override
  State<Setting> createState() => _SettingState();
}

class _SettingState extends State<Setting> {
  bool auto = true;

  bool notice = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorsUtils.rgba(245, 245, 245),
      appBar: BrnAppBar(
        backgroundColor: ColorsUtils.rgba(255, 110, 83, 1),
        title: Text('设置', style: StylesUtils.customTextStyle(fontSize: Sizes.default18)),
        elevation: 0,
        titleAlignment: Alignment.center,
        themeData: BrnAppBarConfig(
          iconSize: Sizes.default20,
          leadIconBuilder: () {
            return ToolsUtils.getAssetImageIcon('back.png');
          },
          leftAndRightPadding: Sizes.default10,
          titlePadding: EdgeInsets.zero,
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
                height: Sizes.default50,
                margin: const EdgeInsets.only(top: Sizes.default10),
                decoration: const BoxDecoration(
                  color: Colors.white,
                ),
                padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                alignment: Alignment.centerLeft,
                child: InkWell(
                  onTap: () {
                    Get.toNamed(RouteGet.userAccountSecurity);
                  },
                  splashColor: Colors.red[50],
                  highlightColor: Colors.red[100],
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('账号与安全',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color363, fontSize: Sizes.default15)),
                      BrunoTools.getAssetSizeImage(
                          BrnAsset.iconRightArrow, Sizes.default16, Sizes.default16)
                    ],
                  ),
                )),
            Container(
              margin: const EdgeInsets.only(top: Sizes.default10),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Column(
                children: [
                  InkWell(
                    onTap: () {
                      Get.toNamed(RouteGet.userPrinterInfo);
                    },
                    child: Container(
                      height: Sizes.default50,
                      alignment: Alignment.centerLeft,
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(color: ColorsUtils.rgba(153, 153, 153, 0.095)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('云打印机',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color363, fontSize: Sizes.default15)),
                          BrunoTools.getAssetSizeImage(
                              BrnAsset.iconRightArrow, Sizes.default16, Sizes.default16)
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('自动接单',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color363, fontSize: Sizes.default15)),
                        GFToggle(
                          onChanged: (bool? val) {
                            auto = val!;
                            setState(() {});
                          },
                          value: auto,
                          type: GFToggleType.ios,
                          boxShape: BoxShape.circle,
                          enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                          enabledThumbColor: Colors.white,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              padding: const EdgeInsets.symmetric(
                  horizontal: Sizes.default15, vertical: Sizes.default10),
              alignment: Alignment.centerLeft,
              child: Text(
                '开启自动接单后，有新订单时自动打印订单，并变更订单状态为配送中，节约订单处理时间。',
                style: StylesUtils.customTextStyle(
                    fontSize: Sizes.default12, color: ColorsUtils.color999),
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: Sizes.default10),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Column(
                children: [
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    decoration: BoxDecoration(
                        border: Border(
                            bottom: BorderSide(color: ColorsUtils.rgba(153, 153, 153, 0.095)))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('消息通知',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color363, fontSize: Sizes.default15)),
                        GFToggle(
                          onChanged: (bool? val) {
                            notice = val!;
                            setState(() {});
                          },
                          value: notice,
                          type: GFToggleType.ios,
                          boxShape: BoxShape.circle,
                          enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                          enabledThumbColor: Colors.white,
                        ),
                      ],
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      Get.toNamed(RouteGet.userPrivacyManage);
                    },
                    child: Container(
                      height: Sizes.default50,
                      alignment: Alignment.centerLeft,
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(color: ColorsUtils.rgba(153, 153, 153, 0.095)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('隐私管理',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color363, fontSize: Sizes.default15)),
                          BrunoTools.getAssetSizeImage(
                              BrnAsset.iconRightArrow, Sizes.default16, Sizes.default16)
                        ],
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      Get.toNamed(RouteGet.userAboutUs);
                    },
                    child: Container(
                      height: Sizes.default50,
                      alignment: Alignment.centerLeft,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('关于我们',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color363, fontSize: Sizes.default15)),
                          BrunoTools.getAssetSizeImage(
                              BrnAsset.iconRightArrow, Sizes.default16, Sizes.default16)
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
            Container(
                height: Sizes.default50,
                margin: const EdgeInsets.only(top: Sizes.default10),
                decoration: const BoxDecoration(
                  color: Colors.white,
                ),
                alignment: Alignment.center,
                child: TextButton(
                  onPressed: () async {
                    await SpUtils.remove('is_login');
                    Get.toNamed(RouteGet.userLoginLogin);
                  },
                  child: Text(
                    '退出登录',
                    textAlign: TextAlign.center,
                    style: StylesUtils.customTextStyle(
                        color: ColorsUtils.colorFf68, fontSize: Sizes.default15),
                  ),
                ))
          ],
        ),
      ),
    );
  }
}
